import math


def cot(theta):
    '''定义cot运算'''
    return math.cos(theta) / math.sin(theta)


def cotSkimming(angel, theta, delta):
    '''计算斜交剖面上下山移动角'''
    cotPie = math.sqrt(cot(angel) * cot(angel) * math.cos(theta) * math.cos(theta) + cot(delta) * cot(delta) * math.sin(
        theta) * math.sin(theta))
    return cotPie


def upLineLength(hi, h, alpha, theta, beta, gamma, delta):
    '''
        function：计算上山方向垂线长度
        hi:即Hi，各角点出的煤层埋深，m
        h：松散层厚度，m
        alpha：煤层倾角
        theta:松散层受护面积边界与煤层走向所夹的锐角
        beta：下山移动角
        gamma：上山移动角
        delta：走向移动角

    '''
    cotB = cotSkimming(beta, theta, delta)
    # cotR = cotSkimming(gamma, theta, delta)
    q = (hi - h) * cotB / (1 + cotB * math.tan(alpha) * math.cos(theta))
    return q


def downLineLength(hi, h, alpha, theta, beta, gamma, delta):
    '''
        function:计算下山方向垂线长度
        hi:即Hi，各角点出的煤层埋深，m
        h：松散层厚度，m
        alpha：煤层倾角
        theta:松散层受护面积边界与煤层走向所夹的锐角
        beta：下山移动角
        gamma：上山移动角
        delta：走向移动角

    '''
    # cotB = cotSkimming(beta, theta, delta)
    cotR = cotSkimming(gamma, theta, delta)
    l = (hi - h) * cotR / (1 - cotR * math.tan(alpha) * math.cos(theta))
    return l


'''请将数据放在垂线长.txt中，数据顺序hi h alpha theta beta gamma delta'''
if __name__ == '__main__':
    f = open("垂线长.txt", "r")
    w = open("垂线长_结果.txt", "w")
    field = f.readline()
    print(field)
    if field == "hi h alpha theta beta gamma delta\n":
        print("字段相同")
        while field:
            print(field)
            field = f.readline()
            if field == "": break
            data = field.split(" ")
            hi = float(data[0])
            h = float(data[1])
            alpha = float(data[2])
            theta = float(data[3])
            beta = float(data[4])
            gamma = float(data[5])
            delta = float(data[6])
            q = upLineLength(hi, h, alpha, theta, beta, gamma, delta)
            l = downLineLength(hi, h, alpha, theta, beta, gamma, delta)
            write = str(hi) + " " + str(h) + " " + str(alpha) + " " + str(theta) + " " + str(beta) + " " + str(
                gamma) + " " + str(delta) + " " + str(q) + " " + str(l) + "\n"
            w.write(write)
    else:
        print("请检查您的参数顺序是否为hi h alpha theta beta gamma delta")
    w.flush()
    w.close()
    f.close()
